package io.yanglong.aiassistant.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.yanglong.aiassistant.agent.DocumentAgent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Tag(name = "文档接口", description = "文档接口")
@RestController
@RequestMapping("doc")
public class DocController {
    private final DocumentAgent documentAgent;

    @Autowired
    public DocController(DocumentAgent documentAgent) {
        this.documentAgent = documentAgent;
    }

    /**
     * 将请求的字符串文本进行向量化
     *
     * @param content 需要向量化的文本
     * @return 是否执行成功
     */
    @Operation(summary = "文档向量化", description = "把字符串文档进行向量化并存储", tags = "文档接口", parameters = {
            @Parameter(name = "content", description = "字符串文档", required = true)
    })
    @PostMapping("embedding")
    public ResponseEntity<Boolean> embedding(@RequestParam("content") String content) {
        return ResponseEntity.ok(documentAgent.embeddingDocByPlain(content));
    }

    /**
     * 根据用户问题回答答案
     *
     * @param userId   用户id
     * @param question 用户问题
     * @return 答案
     */
    @Operation(summary = "文档搜索", description = "进行文档搜索", tags = "文档接口", parameters = {
            @Parameter(name = "userId", description = "用户ID", required = true),
            @Parameter(name = "question", description = "用户问题", required = true)
    })
    @GetMapping("search")
    public ResponseEntity<String> search(@RequestParam("userId") String userId, @RequestParam("question") String question) {
        return ResponseEntity.ok(documentAgent.search(userId, question));
    }
}
